#include "StdAfx.h"
#include "RadarObj.h"
#include "RadarDisObj.h"

//CRadarObj::CRadarObj(void)
//{
//}


CRadarObj::~CRadarObj(void)
{

}

CRadarObj::CRadarObj( CEntityObj *pParent )
	:CActiveComponentObj(pParent)
{
	m_ActiveComponentType =  ACTIVE_COMPONENT_RADAR;
	m_emState = RadarState::Radar_Default;
}

CRadarObj::CRadarObj( CRadarObj *pChartObj )
	:CActiveComponentObj(pChartObj)
{
	m_ActiveComponentType = pChartObj->GetActiveComponentType();
	m_strPathName = pChartObj->m_strPathName;
	m_emState = pChartObj->m_emState;
}

void CRadarObj::RefreshResourcePath()
{
	DriveParamData tmpData = GetDriveParamData();
	m_emState = (RadarState)(int)tmpData.dblValue;
	int n = m_strPathName.ReverseFind(_T('\\'));
	if(-1 == n)return;
	switch(m_emState)
	{
		case RadarState::Radar_Default:
			m_strPathName = m_strPathName.Left(n)+_T("\\Radar_default.jpg");
			break;
		case RadarState::Radar_Recv:
			m_strPathName = m_strPathName.Left(n)+_T("\\Radar_recv.jpg");
			break;
		case RadarState::Radar_Send:
			m_strPathName = m_strPathName.Left(n)+_T("\\Radar_send.jpg");
			break;
        case RadarState::Radar_Send_Recv:
            m_strPathName = m_strPathName.Left(n)+_T("\\Radar_send_recv.jpg");
            break;
	}
}

void CRadarObj::Serialize( CArchive & ar )
{
	if(ar.IsStoring())
	{
		CObj::WriteString(ar,m_strPathName);
	}
	else
	{
		CObj::ReadString(ar,m_strPathName);
	}
	CActiveComponentObj::Serialize(ar);
}

CDisplayObj * CRadarObj::CreateDisplayObj( long lLayerId )
{
	CRadarDisObj *pChartDisObj = new CRadarDisObj(this);
	pChartDisObj->SetLayerId(lLayerId);

	for(auto it = m_ShapeList.begin();it!=m_ShapeList.end();++it)
	{
		(*it)->CreateDisplayObj(lLayerId);
	}
	return pChartDisObj;
}
